var userInfo = new Object();
//var userOrganId = parseInt($("#headUserOrganId").val());
//userInfo.headerUrl = $("#headHeaderUrl").val();
//userInfo.chineseName = $("#headChineseName").val();
userInfo.userAccount = $("#headUserAccount").val();
var userAccount = document.getElementById("headUserName");
//var headerImg = document.getElementById("headerImg");
var userInfoArea = document.getElementById("userInfoArea");
if(userInfo.userAccount!=""){
	$('#headUserName').html(userInfo.userAccount)
}else{
	userInfoArea.innerHTML = "<a href='"+basePath+"'login/login.jsp' style='color:#fff;'>请登录</a>";
}
// Log out
var s = 2;
function SignOut(){
	$.ajax({
        type: "POST",
        url: basePath+"user/logout.do",
        success: function (data) {
            if (data.returnCode==10000) {
            	lDelCookie("returnPageUrl");
            	s = 2;
            	var urls = basePath+"login/login.jsp";
                setTimeout("javascript:location.href='"+urls+"'", 3000);
            	setInterval("run()", 1000);
                layer.msg("退出成功！<strong class='theCountdown'>"+s+"</strong> 秒后前往登录页",50,-1);
            } else if(data.returnCode==999994){
                setUserTimeout(data);
            }else{
            	layer.msg(data.returnMessage,1,-1);
            }
        },
        error: function (message) {
          	 layer.msg("失败",2,-1);
        }
    });
}
function run(){
	s -=1;
	if (s>=0) $(".theCountdown").html(s);
}

$("#signOutBtn").live("click",function(){
	SignOut();
});

function setUserTimeout(data){
	var urls = data.returnData;
    setTimeout("javascript:location.href='"+urls+"'", 3000);
    s = 2;
    setInterval("run()", 1000);
    layer.msg(data.returnMessage+"！<strong class='theCountdown'>"+s+"</strong> 秒后前往登录页",50,-1);
    returnPageUrl();
}
//获取页面的Url并添加至cookie
function returnPageUrl(){
	var returnUrl = window.location.href;
	lSetCookie("returnPageUrl",returnUrl,"1");
}
//两个参数，一个是cookie名，一个是值
function lSetCookie(cname,cvalue,exdays){
  var d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  var expires = "expires="+d.toUTCString();
  document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/";
  //document.cookie="cart="+item_detail+";expires=" + Then.toGMTString() + ";path=/"; 
}
//删除
function lDelCookie(name){ 
	lSetCookie(name, "", -1);  
}

//取cookies函数       
function lGetCookie(name){
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
    return unescape(arr[2]); 
else 
    return null; 
}
$('.openAdd').live('click',function(){
	var maxH=$(window).height()*0.9<700?700:$(window).height()*0.9;
	var maxW=$(window).width()*0.9>1380?1380:$(window).width()*0.9;
	var t=$(this),
		ad=t.attr('data-url');

	var osf=$.layer({
        type : 2,
        title: '新增信息方案',
        shadeClose: false,
        maxmin: false,
        fix : false,  
        area: [maxW, maxH],                     
        iframe: {
            src : ad
        } 
   	 });
});

$('.openF').live('click',function(){ 
	var maxH=$(window).height()*0.9<700?700:$(window).height()*0.9;
	var	maxW=$(window).width()*0.9>1200?1200:$(window).width()*0.9;
	var t=$(this),
		ad=t.attr('data-url');

	var osf=$.layer({
        type : 2,
        title: '编辑信息',
        shadeClose: false,
        maxmin: false,
        fix : false,  
        area: [maxW, maxH],                     
        iframe: {
            src : ad
        } 
   	 });
});

$('.openR').live('click',function(){ 
	var maxH=$(window).height()*0.9<760?760:$(window).height()*0.9;
	var	maxW=$(window).width()*0.9>1200?1200:$(window).width()*0.9;
	var t=$(this),
		ad=t.attr('data-url');

	var osf=$.layer({
        type : 2,
        title: '编辑报告模板',
        shadeClose: false,
        maxmin: false,
        fix : false,  
        area: [maxW, maxH],                     
        iframe: {
            src : ad
        } 
   	 });
});

//编辑信息修改的浮层
$('.editUpdate').live('click',function(){
	var maxH=$(window).height()*0.9<700?700:$(window).height()*0.9;
	var	maxW=$(window).width()*0.9>1380?1380:$(window).width()*0.9;
	var t=$(this),
		ad=t.attr('data-url');

	var osf=$.layer({
        type : 2,
        title: '信息方案编辑',
        shadeClose: false,
        maxmin: false,
        fix : false,  
        area: [maxW, maxH],                     
        iframe: {
            src : ad
        } 
   	 });
});

//编辑信息方案的浮层
$('.editColumn').live('click',function(){ 
//	var maxH=$(window).height()*0.5<300?300:$(window).height()*0.8;
//		maxW=$(window).width()*0.9>500?500:$(window).width()*0.5;
	var t=$(this),
		ad=t.attr('data-url');

	var osf=$.layer({
        type : 2,
        title: '编辑信息方案',
        shadeClose: false,
        maxmin: false,
        fix : false,  
        area: [800, 600],                     
        iframe: {
            src : ad
        } 
   	 });
});

//编辑资源调配模块浮层
$('.srcLayer').live('click',function(){ 
//	var maxH=$(window).height()*0.9<600?600:$(window).height()*0.9;
//		maxW=$(window).width()*0.9>1400?1400:$(window).width()*0.9;
	var t=$(this),
		ad=t.attr('data-url');

		var osf=$.layer({
            type : 2,
            title: '编辑信息',
            shadeClose: false,
            maxmin: false,
            fix : false,  
            area: [800, 500],                     
            iframe: {
                src : ad
            } 
       	 });
});

$('.openTit').live('click',function(){ 
	var maxH=$(window).height()*0.9<700?700:$(window).height()*0.9;
	var	maxW=$(window).width()*0.9>1380?1380:$(window).width()*0.9;
	var ifmNameT = $(this).parent().siblings().eq(0).children().text();
	var ifmNoteT = $(this).parent().siblings().eq(1).children().attr('title');
	var t=$(this),
		ad=t.attr('data-url'); 
	var osf=$.layer({
        type : 2,
        title: ifmNameT+" -- "+ifmNoteT,
        shadeClose: false,
        maxmin: false,
        fix : false,  
        area: [maxW, maxH],                     
        iframe: {
            src : ad
        } 
   	});
});

$('.openSrc').live('click',function(){ 
	var	maxW=$(window).width()*0.9>1200?1200:$(window).width()*0.9;
	var t=$(this),
		ad=t.attr('data-url');

	var osf=$.layer({
        type : 2,
        title: '编辑信息',
        shadeClose: false,
        maxmin: false,
        fix : false,  
        area: [maxW, 500],                     
        iframe: {
            src : ad
        } 
   	 });
});

//禁止backspace可能默认进行页面的后退功能
//document.onkeydown = function(){ 
//	if (event.keyCode == 8) { 
//		if (document.activeElement.type == "text") {
//			if (document.activeElement.readOnly == false)
//				return true; 
//		} 
//		return false;
//	} 
//}  
